package common

import (
	"log"
	"os"
	"path"
	"path/filepath"
	"runtime"
)

// OSType Windows->True
func OSType() bool {
	sysType := runtime.GOOS
	if sysType == "windows" {
		return true
	} else {
		return false
	}
}

func currentAbPathBySourceFile() string {
	var abPath string
	_, filename, _, ok := runtime.Caller(0)
	if ok {
		abPath = path.Dir(filename)
	}
	/* 去除 /common，获取项目根路径 */
	abPath = abPath[:len(abPath)-6]
	return abPath
}

func currentAbPathByExecutable() string {
	exePath, err := os.Executable()
	if err != nil {
		log.Fatal(err)
	}
	res, _ := filepath.EvalSymlinks(filepath.Dir(exePath))
	return res
}

func AbsolutPath() string {
	if DEBUG_MODE {
		return currentAbPathBySourceFile()
	} else {
		return currentAbPathByExecutable()
	}

}
